package ru.ifmo.contest.games;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author avhaliullin
 */
public class TaskDGen {
    int n = 300;
    Boolean[] win = new Boolean[n * n * n];
    int[] step = new int[n * n * n];

    class C {
        C(int val, int pos) {
            this.val = val;
            this.pos = pos;
        }

        int val;
        int pos;
    }

    private boolean test(int a, int b, int c) {
        int[] src1 = new int[]{a, b, c};
        int src2[] = src1.clone();
        int m[] = new int[]{1, 1, 1};
        for (int i = 0; i < 3; i++) {
            while (src2[i] % 2 == 0) {
                src2[i] /= 2;
                m[i] *= 2;
            }
        }
        int num = (src2[0] ^ src2[1] ^ src2[2]) - 1;
        if (num == 0) {
            return false;
        }
        int i = 0;
        List<C> list = new ArrayList<C>();
        list.add(new C(src2[i], i++));
        list.add(new C(src2[i], i++));
        list.add(new C(src2[i], i));
        Collections.sort(list, new Comparator<C>() {
            @Override
            public int compare(C o1, C o2) {
                return o1.val - o2.val;
            }
        });
        src2[list.get(2).pos] = ((list.get(2).val ^ num)) * m[list.get(2).pos];
        while ((src1[list.get(2).pos] - 1) / 2 > (src2[list.get(2).pos] - 1)) {
            src2[list.get(2).pos] *= 2;
        }
        src1[list.get(2).pos] = src2[list.get(2).pos];
        if (test(src1[0], src1[1], src1[2]) || ((src1[0] - 1) < (a - 1) / 2) || ((src1[1] - 1) < (b - 1) / 2) || ((src1[2] - 1) < (c - 1) / 2)
                || ((src1[0] == a ? 0 : 1) + (src1[1] == b ? 0 : 1) + (src1[2] == c ? 0 : 1) != 1)) {
            System.out.println(String.format("bug at %d %d %d", a, b, c));
            throw new AssertionError();
        }
        return true;
    }

    boolean resolve(int a, int b, int c) {
        int pos = a * n * n + b * n + c;
        if (win[pos] == null) {
            for (int i = 1; i <= a / 2; i++) {
                if (!resolve(a - i, b, c)) {
                    win[pos] = true;
                    step[pos] = (a - i) * n * n + (b) * n + c;
                }
            }
            for (int i = 1; i <= b / 2; i++) {
                if (!resolve(a, b - i, c)) {
                    win[pos] = true;
                    step[pos] = (a) * n * n + (b - i) * n + c;
                }
            }
            for (int i = 1; i <= c / 2; i++) {
                if (!resolve(a, b, c - i)) {
                    win[pos] = true;
                    step[pos] = (a) * n * n + (b) * n + c - i;
                }
            }
            if (win[pos] == null) {
                win[pos] = false;
            }
            return win[pos];
        } else {
            return win[pos];
        }
    }

    public void run() {
        int count = 0;
        win[n * n + n + 1] = false;
        resolve(n - 1, n - 1, n - 1);
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < n; j++) {
                for (int k = 1; k < n; k++) {
//                    if (!win[i * n * n + j * n + k]) {
//                    System.out.println(String.format("(%d, %d, %d)  ", i + 1, j + 1, k + 1));
                    if (win[i * n * n + j * n + k] ^ test(i + 1, j + 1, k + 1)) {
                        System.out.println(String.format("bug at %d %d %d", i + 1, j + 1, k + 1));
                        throw new AssertionError();
                    }
//                        count++;
//                    }
//                    System.out.println(String.format("(%d, %d, %d) - ", i, j, k) + String.valueOf(win[i * n*n + j * n + k]));
                }
            }
        }
        System.out.println(count);
    }

    public static void main(String[] args) {
        new TaskDGen().run();
    }

}
